#define _CRT_SECURE_NO_WARNINGS 1
//stock00.cpp -- implementing he Stock class
//version 00;
#include<iostream>
#include"stock00.h"

void Stock::acquire(const std::string& co, long n, double pr)
{
	company = co;
	if (n < 0)
	{
		std::cout << "Number of shares can't be negative." << company << "shares set to 0." << std::endl;
		shares = 0;
	}
	else
		shares = n;
	share_val = pr;
	set_tot();
}
void Stock::buy(long num, double price)
{
	if (num < 0)
	{
		std::cout << "Num of shares purchased can't be negative." << std::endl << "Transaction is aborted.\n" << std::endl;
	}
	else
	{
		shares += num;
		share_val = price;
		set_tot();
	}
}
void Stock::sell(long num, double price)
{
	using std::cout;
	if (num < 0)
	{
		cout << "Number of shares sold can't be negaticve" << std::endl << "Transaction is aborted." << std::endl;
	}
	else if(num>shares)
	{
		cout << "You can't sell more than you have!\n" << "Transaction is aborted.\n";
	}
	else
	{
		shares -= num;
		share_val = price;
		set_tot();
	}
}
void Stock::update(double price)
{
	share_val = price;
	set_tot();
}
void Stock::show()
{
	std::cout << "Company:" << company << std::endl << "Shares:" << shares << '\n' << "Shares price:$" << share_val << '\n' << "Total Worth:$" << total_val << std::endl;
}